home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Taifun / Taifun 117 (1989-11-15)(Ossowski, Stefan)(DE)(PD).zip / Taifun 117 (1989-11-15)(Ossowski, Stefan)(DE)(PD).adf / PrintIt / PrintIt.mod < prev    next >
Text File  |  1989-08-20  |  15KB  |  454 lines

  1. (*---------------------------------------------------------------------------
  2.     :Program.    PrintIt.mod
  3.     :Author.     Fridtjof Siebert
  4.     :Address.    Nobileweg 67, D-7-Stgt-40
  5.     :Phone.      0711/822509
  6.     :Shortcut.   [fbs]
  7.     :Version.    1.0
  8.     :Date.       14-Jul-88
  9.     :Copyright.  PD
  10.     :Language.   Modula-II
  11.     :Translator. M2Amiga
  12.     :Imports.    IFFLoad  [fbs] (Amok#2 or Amok#3).
  13.     :UpDate.     none.
  14.     :Contents.   Utility to create high-quality Hardcopies Epson-Printers.
  15.     :Remark.     Welche Drucker (außer Citizen 120D) können 144 dots/inch ??
  16. ---------------------------------------------------------------------------*)
  17.  
  18. (*-------------------------------------------------------------------------*)
  19. (*                                                                         *)
  20. (*                     =   =   =   PrintIt !   =   =   =                   *)
  21. (*                                                                         *)
  22. (*  A Graphics-Print Utilities for Epson FX-compatible Printers that       *)
  23. (*  use the ESC/P Standard codes. They should be able to print in          *)
  24. (*  quadruple density.                                                     *)
  25. (*                                                                         *)
  26. (*  This Programm allows you to make really black Hardcopies. It uses      *)
  27. (*  the highest possible horizontal & vertical density, i.e. 240 dpi       *)
  28. (*  and 216 dpi. Your Hardcopys will be stretched a bit (11% higher than   *)
  29. (*  they should be) but this normally isn't too important.                 *)
  30. (*                                                                         *)
  31. (*  PrintIt uses PAR: to print. So don't plug your Printer into SER: (I    *)
  32. (*  don't know, if that is possible, but don't do it!).                    *)
  33. (*                                                                         *)
  34. (*  PrintIt has been developed on a Citizen 120D, which is a very cheap,   *)
  35. (*  but good Printer. If you use other Epson compatible Printers, there    *)
  36. (*  should be no problems. Tell me if there are any !!!                    *)
  37. (*                                                                         *)
  38. (*  © 1988 by Fridtjof Siebert                                             *)
  39. (*            Nobileweg 67                                                 *)
  40. (*            D-7000-Stuttgart-40                                          *)
  41. (*            Phone: (0)711/822509                                         *)
  42. (*                                                                         *)
  43. (*  Contributions wellcome.                                                *)
  44. (*                                                                         *)
  45. (*-------------------------------------------------------------------------*)
  46.  
  47. MODULE PrintIt;
  48.  
  49. (*--------------------------  IMPORTs:  -----------------------------------*)
  50.  
  51. (*------  SYSTEM:  ------*)
  52. FROM SYSTEM         IMPORT ADR, SHIFT, BITSET, INLINE;
  53. FROM Arts           IMPORT TermProcedure, Assert;
  54. FROM Arguments      IMPORT GetArg, NumArgs;
  55.  
  56. (*------  Libraries:  ------*)
  57. FROM Dos            IMPORT Open, Close, FileHandlePtr, Write, Read, oldFile,
  58.                            newFile, Delay;
  59. FROM Exec           IMPORT AllocMem, FreeMem, MemReqs, MemReqSet, UByte,
  60.                            WaitPort, GetMsg, ReplyMsg;
  61. FROM Graphics       IMPORT SetDrMd, SetAPen, SetBPen, Move, Text, jam2,
  62.                            RectFill;
  63. FROM Intuition      IMPORT ScreenPtr, WindowPtr, CloseScreen, CloseWindow,
  64.                            IntuiMessagePtr, GadgetPtr, IDCMPFlags,
  65.                            ScreenToFront, WBenchToFront, SetPointer,
  66.                            ClearPointer, RemoveGadget, AddGadget;
  67.  
  68. (*------  Own stuff:  ------*)
  69. FROM IFFSupport     IMPORT ReadILBM, ReadILBMFlags, ReadILBMFlagSet, IFFInfo;
  70. (* IFFLoad from AMOK#2 or #3 *)
  71. FROM PrintItDisplay IMPORT OpenPrintIt, Window, Gadgets, RP, TextType,
  72.                            GetName, InitPrintIt, StretchX, StretchY,
  73.                            DoublePrint, xRes, yRes, Positive, PixName,
  74.                            Screen, Convert, StrInfo, Buffers, Gadgs;
  75.  
  76. (*-----------------------  Variables:  ------------------------------------*)
  77.  
  78. TYPE
  79.   BufferType = ARRAY[0..8249] OF UByte; (* I/O Buffer for PAR: *)
  80.  
  81. VAR
  82.   MyFile: FileHandlePtr;                (* FileHandlePtr for PAR: *)
  83.   Buffer: POINTER TO BufferType;        (* It's Buffer            *)
  84.   DummyWindow: WindowPtr;               (* not too important      *)
  85.   ok: BOOLEAN;
  86.   i: CARDINAL;
  87.   j: INTEGER;
  88.   len: LONGINT;
  89.   ActLine, CountLines, CountBits, CountBytes: CARDINAL; (* Count anything *)
  90.   RepHorCnt,RepVerCnt: LONGINT;         (* Count Repeats          *)
  91.   ActByte: UByte;                       (* the calcylated Byte    *)
  92.   ActAdr: POINTER TO BITSET;            (* Position in BitMap     *)
  93.   SmallOrBig: CARDINAL;                 (* Counts Printed lines   *)
  94.   Msg: IntuiMessagePtr;
  95.   Gadget: GadgetPtr;
  96.   WaitPointer,DataPtr: POINTER TO ARRAY[0..17] OF LONGCARD;
  97.   IDCount: Gadgets;
  98.  
  99. (*-------------------------------------------------------------------------*)
  100. (*                                                                         *)
  101. (*                        The Main Print-Procedure                         *)
  102. (*                                                                         *)
  103. (*-------------------------------------------------------------------------*)
  104.  
  105. PROCEDURE PrintIt();
  106.  
  107. VAR
  108.   Ende: BOOLEAN;
  109.  
  110. BEGIN
  111.  
  112.   RepVerCnt := 0;
  113.   REPEAT
  114.  
  115. (*------  Set LF:  ------*)
  116.  
  117.     Buffer^[0] := 1BH;
  118.     CASE yRes OF
  119.     DpiV72ID:
  120.       Buffer^[1] := 33H; Buffer^[2] := 23;
  121.       len := Write(MyFile,Buffer,3); |
  122.     DpiV144ID:
  123.       Buffer^[1] := 7EH; Buffer^[2] := 30H; Buffer^[3] := 1;
  124.       len := Write(MyFile,Buffer,4); |
  125.     DpiV216ID:
  126.       Buffer^[1] := 33H; Buffer^[2] := 1;
  127.       len := Write(MyFile,Buffer,3);
  128.     END;
  129.  
  130. (*------  Main Printing-Loop:  ------*)
  131.  
  132.     CountLines := 0;  (* Line 0                 *)
  133.     SmallOrBig := 0;  (* Counts small or big LF *)
  134.  
  135.     Ende := FALSE;
  136.  
  137.     WITH Screen^.bitMap DO
  138.  
  139. (*------  LOOP for Lines:  ------*)
  140.  
  141.       WHILE ((CountLines DIV StretchY) < rows) AND NOT(Ende) DO
  142.  
  143.         CountBytes := 0; (* Num of Bytes printed per Line *)
  144.         CountBits := 0;  (* x-Position in BitMap          *)
  145.  
  146. (*------  LOOP to print a Line:  ------*)
  147.  
  148.         WHILE SHIFT(CountBits,-3) < bytesPerRow DO
  149.  
  150.           ActByte := 0;
  151.           i := 0;
  152.  
  153. (*------  LOOP to get 8 Bits:  ------*)
  154.  
  155.           LOOP
  156.  
  157.             CASE yRes OF
  158.               DpiV72ID : ActLine := CountLines + i; |
  159.               DpiV144ID: ActLine := CountLines + i+i; |
  160.               DpiV216ID: ActLine := CountLines + i+i+i; |
  161.             END;
  162.             ActLine := ActLine DIV StretchY;
  163.             IF ActLine >= rows THEN EXIT END;
  164.  
  165.             ActByte := SHIFT(ActByte,1);
  166.             ActAdr := planes[0];
  167.             INC(ActAdr,LONGCARD(ActLine) * LONGCARD(bytesPerRow)
  168.                + SHIFT(SHIFT(CountBits,-4),1));
  169.  
  170.             IF 15 - (CountBits-SHIFT(SHIFT(CountBits,-4),4)) IN ActAdr^ THEN
  171.               INC(ActByte,1); (* Bit Set *)
  172.             END;
  173.  
  174.             INC(i);
  175.             IF i=8 THEN EXIT END;
  176.  
  177.           END;
  178.  
  179.           IF NOT(Positive) THEN
  180.             CASE i OF
  181.               8: ActByte := 255-ActByte; |
  182.               7: ActByte := 127-ActByte; |
  183.               6: ActByte :=  63-ActByte; |
  184.               5: ActByte :=  31-ActByte; |
  185.               4: ActByte :=  15-ActByte; |
  186.               3: ActByte :=   7-ActByte; |
  187.               2: ActByte :=   3-ActByte; |
  188.               1: ActByte :=   1-ActByte; |
  189.             END;
  190.           END;
  191.           ActByte := SHIFT(ActByte,8-i);
  192.  
  193.           i := 0;
  194.           REPEAT
  195.             Buffer^[CountBytes+5] := ActByte; (* Byte to Printer's Buffer *)
  196.             INC(CountBytes); (* Next Byte to Printer *)
  197.             INC(i);
  198.           UNTIL i=StretchX; (* Byte StretchX times into Buffer *)
  199.           INC(CountBits);  (* 1 Pixel to the right *)
  200.  
  201.         END;
  202.  
  203. (*------  Print one Line:  ------*)
  204.  
  205.         Buffer^[0] := 1BH; Buffer^[1] := 2AH;
  206.         CASE xRes OF
  207.           DpiH60ID:  Buffer^[2] := 0; |
  208.           DpiH72ID:  Buffer^[2] := 5; |
  209.           DpiH80ID:  Buffer^[2] := 4; |
  210.           DpiH90ID:  Buffer^[2] := 6; |
  211.           DpiH120ID: Buffer^[2] := 1; |
  212.           DpiH144ID: Buffer^[2] := 7; |
  213.           DpiH240ID: Buffer^[2] := 3; |
  214.         END;
  215.         Buffer^[3] := UByte(CountBytes - SHIFT(SHIFT(CountBytes,-8),8));
  216.         Buffer^[4] := UByte(SHIFT(CountBytes,-8));
  217.         Buffer^[CountBytes+5] := 0DH; (* CR *)
  218.         Buffer^[CountBytes+6] := 0AH; (* LF *)
  219.         IF DoublePrint THEN
  220.           RepHorCnt := 0;
  221.           REPEAT
  222.             len := Write(MyFile,Buffer,CountBytes+5);      (* Print Line *)
  223.             INC(RepHorCnt);
  224.           UNTIL RepHorCnt >= StrInfo[RepHorID].longInt;
  225.           len := Write(MyFile,ADR(Buffer^[CountBytes+5]),1); (* CR *)
  226.         END;
  227.         RepHorCnt := 0;
  228.         REPEAT
  229.           len := Write(MyFile,Buffer,CountBytes+5);        (* Print Line *)
  230.           INC(RepHorCnt);
  231.         UNTIL RepHorCnt >= StrInfo[RepHorID].longInt;
  232.         len := Write(MyFile,ADR(Buffer^[CountBytes+5]),2); (* CR + LF *)
  233.  
  234. (*------  Increase CountLines and set next LF-Size:  ------*)
  235.  
  236.         INC(SmallOrBig);
  237.         CASE yRes OF
  238.         DpiV72ID:
  239.           INC(CountLines,8); |
  240.         DpiV144ID:
  241.           Buffer^[0] := 1BH; Buffer^[1] := 7EH;
  242.           Buffer^[2] := 30H;
  243.           CASE SmallOrBig OF
  244.           2: SmallOrBig := 0;
  245.              INC(CountLines,15);
  246.              Buffer^[3] := 1;  |
  247.           1: INC(CountLines);
  248.              Buffer^[3] := 15; |
  249.           END;
  250.           len := Write(MyFile,Buffer,4); |
  251.         DpiV216ID:
  252.           Buffer^[0] := 1BH; Buffer^[1] := 33H;
  253.           CASE SmallOrBig OF
  254.           3: SmallOrBig := 0;
  255.              Buffer^[2] := 1H;     (* small LF: 1/216''             *)
  256.              INC(CountLines,22); | (* 3 Lines done: get a bit down. *)
  257.           2: Buffer^[2] := 16H;    (* next is a big LF (22/216'')   *)
  258.              INC(CountLines); |    (* next Line                     *)
  259.           1: Buffer^[2] := 1H;     (* 1/216''                       *)
  260.              INC(CountLines); |    (* next Line                     *)
  261.           END;
  262.           len := Write(MyFile,Buffer,3); (* set LF-Size *)
  263.         END;
  264.  
  265.         Msg := GetMsg(Window^.userPort);
  266.         IF Msg#NIL THEN
  267.           Gadget := Msg^.iAddress;
  268.           ReplyMsg(Msg);
  269.           Ende := Gadgets(Gadget^.gadgetID) = PrintItID;
  270.         END;
  271.  
  272.       END;   (* WHILE (CountLines DIV StretchY) < rows DO *)
  273.  
  274.     END;   (* WITH Screen^.bitMap DO *)
  275.  
  276.     INC(RepVerCnt);
  277.  
  278.   UNTIL (RepVerCnt >= StrInfo[RepVerID].longInt) OR Ende;
  279.  
  280. END PrintIt;
  281.  
  282. (*-----------------------  CleanUp:  --------------------------------------*)
  283.  
  284. PROCEDURE CleanUp();
  285.  
  286. BEGIN
  287.   IF Window#NIL THEN CloseWindow(Window) END;
  288.   IF Screen#NIL THEN CloseScreen(Screen) END;
  289.   IF MyFile#NIL THEN Close(MyFile); END;
  290.   IF Buffer#NIL THEN FreeMem(Buffer,SIZE(Buffer^)) END;
  291.   IF WaitPointer#NIL THEN FreeMem(WaitPointer,SIZE(WaitPointer^)) END;
  292. END CleanUp;
  293.  
  294. (*------  Some Data:  ------*)
  295.  
  296. PROCEDURE PointerData(); (* $E- Contains SpriteData: *)
  297.  
  298. BEGIN
  299.   INLINE(0,0,
  300.          0003FH,00000H,0007FH,00021H,0007FH,00000H,000FEH,00042H,
  301.          000FEH,00000H,001FCH,00084H,001FCH,00000H,003F8H,00108H,
  302.          00FFFH,00C07H,017F1H,01A1FH,027F3H,038CFH,04005H,07FFFH,
  303.          0FFF9H,0FFFFH,0800AH,0FFFEH,0800CH,0FFFCH,0FFF8H,0FFF8H,0,0);
  304. END PointerData;
  305.  
  306. (*---------------------------  MAIN:  -------------------------------------*)
  307.  
  308. BEGIN
  309.  
  310. (*------  Itialization:  ------*)
  311.  
  312.   Screen := NIL;
  313.   MyFile := NIL;
  314.   Buffer := NIL;
  315.   Window := NIL;
  316.   WaitPointer := NIL;
  317.   TermProcedure(CleanUp);
  318.  
  319. (*------  Get Memory for Pointer:  ------*)
  320.  
  321.   WaitPointer := AllocMem(SIZE(WaitPointer^),MemReqSet{chip});
  322.   Assert(WaitPointer#NIL,ADR("Not enough Chip Memory !!!"));
  323.   DataPtr := ADR(PointerData);
  324.   WaitPointer^ := DataPtr^;
  325.  
  326. (*------  Get Argument:  ------*)
  327.  
  328.   IF NumArgs()=0 THEN
  329.     GetName();
  330.   ELSE
  331.     GetArg(1,PixName,j);
  332.   END;
  333.  
  334. (*------  Load Pic:  ------*)
  335.  
  336.   WHILE NOT(ReadILBM(PixName,ReadILBMFlagSet{front,visible},Screen,
  337.         DummyWindow)) DO
  338.     ok := WBenchToFront();
  339.     GetName();
  340.   END;
  341.   ok := WBenchToFront();
  342.   IF Screen^.bitMap.depth > 1 THEN
  343.     Convert();
  344.   END;
  345.  
  346. (*------  Open Window:  ------*)
  347.  
  348.   OpenPrintIt();
  349.   InitPrintIt();
  350.  
  351. (*------  Open PAR:  ------*)
  352.  
  353.   MyFile := Open(ADR("PAR:"),newFile);
  354.   Assert(MyFile#NIL,ADR("Couldn't open PAR: !!!"));
  355.   Buffer := AllocMem(SIZE(BufferType),MemReqSet{chip});
  356.   Assert(Buffer#NIL,ADR("Not enough Chip Memory !!!"));
  357.  
  358. (*------  Get Messages:  ------*)
  359.  
  360.   LOOP
  361.     WaitPort(Window^.userPort);
  362.     Msg := GetMsg(Window^.userPort);
  363.     IF closeWindow IN Msg^.class THEN
  364.       ReplyMsg(Msg);
  365.       EXIT;
  366.     END;
  367.     Gadget := Msg^.iAddress;
  368.     ReplyMsg(Msg);
  369.  
  370.     CASE Gadgets(Gadget^.gadgetID) OF
  371.  
  372.     hori1ID..hori8ID:
  373.       StretchX := Gadget^.gadgetID + 1; |
  374.  
  375.     vert1ID..vert8ID:
  376.       StretchY := Gadget^.gadgetID - 7; |
  377.  
  378.     PrintNormalID:
  379.       DoublePrint := FALSE; |
  380.  
  381.     PrintDoubleID:
  382.       DoublePrint := TRUE; |
  383.  
  384.     PrintItID:
  385.       FOR IDCount := MIN(Gadgets) TO MAX(Gadgets) DO
  386.         IF IDCount#PrintItID THEN
  387.           IF RemoveGadget(Window,ADR(Gadgs[IDCount]))=0 THEN END;
  388.         END;
  389.       END;
  390.       SetDrMd(RP,jam2); SetAPen(RP,0); SetBPen(RP,0);
  391.       RectFill(RP,9,107,119,117); SetAPen(RP,1);
  392.       Move(RP, 24,115); Text(RP,ADR("  Abort!  "),10);
  393.       ScreenToFront(Screen);
  394.       SetPointer(Window,WaitPointer,16,16,-8,-8);
  395.       PrintIt();
  396.       ClearPointer(Window);
  397.       SetAPen(RP,0); RectFill(RP,9,107,119,117); SetAPen(RP,1);
  398.       Move(RP, 24,115); Text(RP,ADR("Print It !"),10);
  399.       FOR IDCount := MIN(Gadgets) TO MAX(Gadgets) DO
  400.         IF IDCount#PrintItID THEN
  401.           IF AddGadget(Window,ADR(Gadgs[IDCount]),0)=0 THEN END;
  402.         END;
  403.       END;
  404.       ok := WBenchToFront(); |
  405.  
  406.     DpiH60ID..DpiH240ID:
  407.       xRes := Gadgets(Gadget^.gadgetID); |
  408.  
  409.     DpiV72ID..DpiV216ID:
  410.       yRes := Gadgets(Gadget^.gadgetID); |
  411.  
  412.     PositiveID:
  413.       Positive := NOT(Positive); |
  414.  
  415.     RepHorID..RepVerID:
  416.       WITH StrInfo[Gadgets(Gadget^.gadgetID)] DO
  417.         IF longInt<1 THEN
  418.           longInt := 1;
  419.         END;
  420.       END; |
  421.  
  422.     LoadPicID:
  423.       CloseScreen(Screen);
  424.       Screen := NIL;
  425.       REPEAT
  426.         ClearPointer(Window);
  427.         GetName();
  428.         SetPointer(Window,WaitPointer,16,16,-8,-8);
  429.       UNTIL ReadILBM(PixName,ReadILBMFlagSet{front,visible},Screen,
  430.             DummyWindow);
  431.       ClearPointer(Window);
  432.       ok := WBenchToFront();
  433.       IF Screen^.bitMap.depth > 1 THEN
  434.         Convert();
  435.       END; |
  436.  
  437.     ResetID:
  438.       StretchX := 1; StretchY := 1;
  439.       DoublePrint := FALSE;
  440.       xRes := DpiH240ID;
  441.       yRes := DpiV216ID;
  442.       Positive := TRUE;
  443.       StrInfo[RepHorID].longInt := 1;
  444.       Buffers[RepHorID] := "1";
  445.       StrInfo[RepVerID].longInt := 1;
  446.       Buffers[RepVerID] := "1"; |
  447.     END;
  448.  
  449.     InitPrintIt();
  450.  
  451.   END; (* LOOP *)
  452.  
  453. END PrintIt. That's it.
  454.